import {Injectable} from '@angular/core';
import {environment} from "../../../../../../environments/environment";
import {BarnDocument} from "../entity/barn-document";
import {Observable} from "rxjs";
import {ResponseEntity} from "../../../../../services/http/response-entity";
import {HttpUtilService} from "../../../../../services/http/http-util.service";

@Injectable({
  providedIn: 'root'
})
export class BarnDocumentService {
  private prefix = environment.serverName.document + "/document/"

  constructor(private http: HttpUtilService) {
  }

  save(data: BarnDocument, handleError = true): Observable<BarnDocument> {
    return this.http.post(this.prefix + "save", data, handleError);
  }

  queryMyDocument(data: BarnDocument, current = 0, pageSize = 0, handleError = true): Observable<ResponseEntity<BarnDocument[]>> {
    return this.http.getPage(this.prefix + "queryMyDocument", current, pageSize, handleError, data)
  }

  getById(pid: string, handleError = true): Observable<BarnDocument> {
    return this.http.get(this.prefix + "getById/" + pid, handleError)
  }

  deleteById(pid: string, handleError = true): Observable<void> {
    return this.http.post(this.prefix + "deleteById", {pid}, handleError)
  }

  query(data: BarnDocument, current = 0, pageSize = 0, handleError = true): Observable<ResponseEntity<BarnDocument[]>> {
    return this.http.getPage(this.prefix + "query", current, pageSize, handleError, data)
  }
}
